package com.qf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.Serializable;
import java.util.Map;

/**
 * 入门程序
 *
 *   public void com.qf.controller.HelloController.hello.(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
 * @author lixu
 */
@Controller
@RequestMapping("/user") //模块名称
public class HelloController {

    /**
     * 第一 :
     */
    @RequestMapping("/hello")
    public void hello(HttpServletRequest request, HttpServletResponse response, HttpSession httpSession)
      throws Exception{
        String id = request.getParameter("id");
        System.out.println("id:" + id);
        httpSession.setAttribute("name","小张");
        request.setAttribute("name","小张");
        request.getRequestDispatcher("/index.jsp").forward(request,response);
        //原生的Request对象来完成 转发jsp页面 并携带数据
    }
    /**
     * 第二：
     */
    @RequestMapping("/view")
    public ModelAndView view() {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("hello");
        mav.addObject("name","小张");
        return mav;
    }
    /**
     * //第三：
     */
/*    @RequestMapping("/h")
    public ModelAndView h() {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("h");
        mav.addObject("name","小张");
        return mav;
    }*/
    /**
     * 第三
     */
    @RequestMapping("/t")
    //public String t(Model model, Map map) {
    public String t(Map map,HttpServletRequest request) {
        map.put("name","成龙");
        request.setAttribute("age",60);

        //内部转发视图
        return "hello";
    }
}
